<template>
  <div class="login-wrapper">
    <!-- 背景层 -->
    <div class="background-overlay"></div>
    <div class="login-card">
      <!-- 登录标题 -->
      <h1 class="login-title">湖文书舍后台</h1>
      <!-- 登录表单 -->
      <form >
        <div class="form-group">
          <!-- 用户名输入框 -->
          <input type="text" id="username" v-model="account" placeholder="请输入用户名" />
          <span class="focus-border"></span>
        </div>
        <div class="form-group">
          <!-- 密码输入框 -->
          <input type="password" id="password" v-model="password" placeholder="请输入密码" />
          <span class="focus-border"></span>
        </div>
        <!-- 登录按钮 -->
        <button type="button" class="login-button" @click="login()">登录</button>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import {baseUrl} from '../../static/js/common.js'
import {onShow} from '@dcloudio/uni-app'

const account = ref('');
const password = ref('');

function login(){
	let params={
		'account':account.value,
		'password':password.value
	}
	uni.request({
		url:baseUrl+'/user/adminLogin',
		data:params,
		method:'POST',
		success:(res)=>{
			if(res.data.code==200){
				localStorage.setItem('user',JSON.stringify(res.data.data))
				
				localStorage.setItem("Authorization",res.data.data.token)
				uni.showToast({
					icon:'success',
					title:'登录成功'
				})
				uni.navigateTo({
					url:'/pages/userIndex/userIndex'
				})
			}else if(res.data.code==400){
				uni.showToast({
					icon:'fail',
					title:'登录失败'
				})
			}
		}
	})
}

onShow(()=>{
	localStorage.removeItem('user')
	localStorage.removeItem("Authorization")
})
</script>

<style scoped>
/* 全局样式 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Poppins', sans-serif;
  /* 设置背景图片，可替换为你自己喜欢的图片链接 */
  background: url('/static/bg.png') no-repeat center center fixed;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

.login-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}

/* 背景遮罩层，增加背景的层次感和可读性 */
/* .background-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
} */

.login-card {
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  padding: 40px;
  width: 380px;
  animation: fadeIn 0.5s ease-in-out;
  z-index: 1;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-title {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.form-group {
  position: relative;
  margin-bottom: 25px;
}

.form-group input {
  width: 100%;
  /* padding: 12px 0; */
  border: none;
  border-bottom: 1px solid #ccc;
  font-size: 16px;
  color: #333;
  outline: none;
  transition: border-color 0.3s ease;
  background-color: transparent;
}

.form-group input:focus {
  border-color: #007bff;
}

.form-group .focus-border {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background-color: #007bff;
  transition: width 0.3s ease;
}

.form-group input:focus + .focus-border {
  width: 100%;
}

.login-button {
  width: 100%;
  padding: 12px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s ease;
  box-shadow: 0 5px 10px rgba(0, 123, 255, 0.3);
}

.login-button:hover {
  background-color: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(0, 123, 255, 0.4);
}
</style>